﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class QLVB_User_DoiMatKhau : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            NguoiDungBUS ndBUS = new NguoiDungBUS();
            string maNguoiDungURL = (String)Session["MaNguoiDung"];
            string matKhauTemp = ndBUS.layMatKhau(maNguoiDungURL);
            txtMatKhauCu.Text = matKhauTemp;
        }
    }

    protected void thaydoiMatKhau()
    {
        string maNguoiDungURL = (String)Session["MaNguoiDung"];

        NguoiDungBUS ndBUS = new NguoiDungBUS();

        MyTextBox myTextBox = new MyTextBox();

        string matKhauTemp = ndBUS.layMatKhau(maNguoiDungURL);
        
        string maKhauCu = myTextBox.mahoaSHA1(txtMatKhauCu);

        string matKhauMoi = myTextBox.mahoaSHA1(txtMatKhauMoi);

        if (myTextBox.kiemtraRong(txtMatKhauCu) == false)
        {
            if (myTextBox.kiemtraRong(txtMatKhauMoi) == false)
            {
                if (myTextBox.kiemtraRong(txtNhapLaiMatKhau) == false)
                {
                    if (maKhauCu == matKhauTemp)
                    {
                        if (txtNhapLaiMatKhau.Text == txtMatKhauMoi.Text)
                        {
                            ndBUS.thaydoiMatKhau(maNguoiDungURL, matKhauMoi);

                            Alert.Show("Da doi mat khau thanh cong");
                        }
                        else
                        {
                            Alert.Show("Mat khau nhap lai khong chinh xac");

                            return;
                        }
                    }
                    else
                    {
                        Alert.Show("Mat khau cu khong chinh xac");

                        return;
                    }
                }
                else
                {
                    Alert.Show("Mat khau nhap lai khong duoc rong");

                    return;
                }
            }
            else
            {
                Alert.Show("Mat khau moi khong duoc rong");

                return;
            }
        }
        else
        {
            Alert.Show("Mat khau cu khong duoc rong");

            return;
        }
    }
    protected void btnDongY_Click(object sender, EventArgs e)
    {
        thaydoiMatKhau();

        //Response.Redirect("~/pHome.aspx");
    }
    protected void btnDong_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/pHome.aspx");
    }
}